﻿using ZYCommon;
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using Bifrost;
using System.Collections.Generic;
using TextEditor.TextDocument.Control;

namespace TextEditor
{


    public class ZYTextInput : ZYTextBlock
    {
        private bool bolValueFormatCheck = true;
        private System.Drawing.Font myFont = null;
        private StringDataFormat myFormat = new StringDataFormat();
        private bool bolPass = false;

        public ZYTextInput()
        {
            this.Width = 6;
            base.myLastElement = new ZYTextInputEnd();
            base.myLastElement.Parent = this;
            base.myChildElements.Clear();
            this.AddLastElement();
            base.myLines.Clear();
            base.LineSpan = -1;
            base.intLeftMargin = 5;
        }

        public bool BolPass
        {
            get
            {
                return (this.IntLength < this.minLength ? true : false);
            }
        }

        public override void AddElementToList(ArrayList myList, bool ResetFlag)
        {
            this.AddLastElement();
            base.AddElementToList(myList, ResetFlag);
            if (this.OwnerDocument.Info.Printing && this.GetLastElement() is ZYTextInputEnd)
            {
                this.ChildElements.Remove(this.GetLastElement());
            }
        }

        protected override void AddLastElement()
        {
            if (!base.myChildElements.Contains(base.myLastElement))
            {
                base.myChildElements.Add(base.myLastElement);
            }
        }

        public override int AppendKeyValueList(ArrayList myKeyValues)
        {
            myKeyValues.Add(base.ID);
            if (ZYKBBuffer.Instance.Loading)
            {
                myKeyValues.Add(base.Name);
            }
            else
            {
                KB_List kBList = ZYKBBuffer.Instance.GetKBList(this.ListSource);
                myKeyValues.Add((kBList == null) ? "0" : kBList.Name);
            }
            myKeyValues.Add(base.ToZYString());
            return 1;
        }

        public override bool CanBeLineEnd()
        {
            return false;
        }

        public override void DrawBackGround(ZYTextElement myElement)
        {
            if (base.bolStandOutBack && !base.myOwnerDocument.Info.Printing)
            {
                if (myElement.OwnerLine != null)
                {
                    switch (this.SelectType)
                    {
                        case "1":
                            Rectangle b = new Rectangle(myElement.RealLeft, myElement.RealTop, myElement.Width, myElement.Height);
                            base.myOwnerDocument.View.FillRectangle(Color.FromArgb(175, Color.DarkSlateGray), b);
                            break;
                        case "0":
                            if (myElement is ZYTextContainer)
                            {
                                if (((ZYTextContainer)myElement).ChildCount > 0 && myElement != this)
                                {
                                    foreach (ZYTextElement var in ((ZYTextContainer)myElement).ChildElements)
                                    {
                                        DrawBackGround(var);
                                    }
                                }
                            }
                            base.myOwnerDocument.View.DrawLine(Color.Red, myElement.RealLeft, myElement.Bounds.Bottom - 1, myElement.Bounds.Right, myElement.Bounds.Bottom - 1);
                            break;
                        case "3":
                            if (this.Name == "普通医师签名" || this.Name == "上级医师签名" || this.Name == "管床医师签名" || this.Name == "转科上级医师签名")
                            {
                                Rectangle b2 = new Rectangle(myElement.RealLeft, myElement.RealTop, myElement.Width, myElement.Height - 1);
                                base.myOwnerDocument.View.FillRectangle(Color.FromArgb(175, Color.DarkGoldenrod), b2);
                            }
                            break;
                    }
                }
            }
            if (this.bolPass)
            {
                base.myOwnerDocument.View.DrawLine(Color.Red, myElement.RealLeft, myElement.Bounds.Bottom - 1, myElement.Bounds.Right, myElement.Bounds.Bottom - 1);
            }
            if (!base.myOwnerDocument.Info.Printing)
            {
                if (this.SelectType == "0")
                {
                    base.myOwnerDocument.View.DrawString("{", this.Font, Color.DeepPink, this.RealLeft - 4, this.RealTop);
                }
                else
                {
                    base.myOwnerDocument.View.DrawString("[", this.Font, Color.DarkCyan, this.RealLeft - 4, this.RealTop);
                }
            }
            if (BorderStyle == 1)
            {
                base.myOwnerDocument.View.DrawLine(Color.Black, myElement.Bounds.Left, myElement.OwnerLine.RealBottom, myElement.Bounds.Right, myElement.OwnerLine.RealBottom);
            }
        }

        public override bool FromXML(XmlElement myElement)
        {
            if (base.FromXML(myElement))
            {
                return true;
            }
            return false;
        }

        public override string GetXMLName()
        {
            return "input";
        }

        public void ShowSelectKnow()
        {
            base.myOwnerDocument.Content.AutoClearSelection = true;
            base.myOwnerDocument.SetSelectToList(this);
        }

        public override bool HandleDblClick(int x, int y, MouseButtons Button)
        {
            if (!base.OwnerDocument.Locked)
            {
                if (this.Contains(x, y))
                {
                    string name = this.Name;
                    if (name == null)
                        return true;
                    if ((this.Name == "请求会诊科目" || this.Name == "接诊时间" || this.Name == "请求会诊时间") && this.Parent.CanDelete)
                    {
                        return true;
                    }
                    if (this.SelectType == "0" || this.SelectType == "1")
                    {
                        base.myOwnerDocument.Content.AutoClearSelection = true;
                        base.myOwnerDocument.SetSelectToList(this);
                    }

                    if (this.ID != null && this.ID.Contains("#sum"))
                    {
                        int num = this.OwnerDocument.Calculate(this.ID);
                        if (num >= 0)
                            this.Text = num.ToString();
                        this.OwnerDocument.ContentChanged();
                        return true;
                    }

                    else if (name == "其他医师签名")
                    {
                        if (string.IsNullOrEmpty(this.ID))
                        {
                            this.ID = App.UserAccount.UserInfo.User_id;
                            this.Text = "        " + App.UserAccount.UserInfo.User_name;
                            this.OwnerDocument.ContentChanged();
                            return true;
                        }
                        else
                        {
                            Class_DocSign firstSign = App.InSerterHighLevelSign("S", this.ID);
                            if (firstSign != null)
                            {
                                this.ID = firstSign.Userid;
                                this.Text = "        " + firstSign.Username;
                                this.OwnerDocument.SaveTrue = true;
                                this.OwnerDocument.ContentChanged();
                                return true;
                            }
                        }
                    }
                    else if (name == "科室" || name == "请求会诊科目")
                    {
                        frmSelectSection fc = new frmSelectSection(this.ID);
                        if (fc.ShowDialog() == DialogResult.OK)
                        {
                            this.ID = fc.SectionId;
                            this.Text = fc.SectionName;
                            this.OwnerDocument.ContentChanged();
                        }
                        fc.Dispose();
                    }
                    else if (name == "手术医师")
                    {
                        frmSelectDoctor selectDoctor = new frmSelectDoctor(this.ID, this.Text);
                        if (selectDoctor.ShowDialog() == DialogResult.OK)
                        {
                            this.ID = selectDoctor.strId;
                            this.Text = selectDoctor.strName;
                            this.OwnerDocument.ContentChanged();
                        }
                        selectDoctor.Dispose();
                    }
                    else if (name.Contains("时间") || name.Contains("日期") || name == "us_rysj" || name == "us_jlrq" || name == "时分" || name == "月日")
                    {
                        base.myOwnerDocument.Content.AutoClearSelection = true;
                        base.myOwnerDocument.SetInputTime(this);
                    }
                    #region 签名相关
                    else if ((name == "普通医师签名")
                        && this.Text.Length > 5)
                    {
                        if (this.Text.Length < 5)
                        {
                            return false;
                        }
                        frmUpdateCancelSign fucs = new frmUpdateCancelSign();
                        fucs.ShowDialog();
                        if (fucs.Revocation)
                        {
                            ArrayList qmList = this.OwnerDocument.GetQmList("普通医师签名");//获取所有的签名元素
                            ZYTextInput firstInput = qmList[0] as ZYTextInput;
                            if (qmList != null && qmList.Count > 0)
                            {
                                if (qmList.Count == 1) //如果只有一个签名,就跳出修改记录者签名框
                                {
                                    Class_DocSign firstSign = App.InSerterHighLevelSign("S", firstInput.ID);
                                    if (firstSign != null)
                                    {
                                        firstInput.ID = firstSign.Userid;
                                        firstInput.Text = "        " + firstSign.Username;
                                        this.OwnerDocument.ContentChanged();
                                        this.OwnerDocument.SaveOk();
                                        return true;
                                    }
                                }
                                else  //如果多个需要把前面的签名都撤销掉才能修改的
                                {
                                    if (this == firstInput)
                                    {
                                        if (this.ID == App.UserAccount.UserInfo.User_id)
                                        {
                                            this.OwnerDocument.RemoveInput(this);
                                            this.OwnerDocument.ContentChanged();
                                            this.OwnerDocument.SaveOk();
                                        }
                                        else
                                        {
                                            Class_DocSign cd = App.InSerterHighLevelSign("S");
                                            if (cd != null)
                                            {
                                                if (cd.Userid == firstInput.ID)
                                                {
                                                    this.OwnerDocument.RemoveInput(this);
                                                    this.OwnerDocument.ContentChanged();
                                                    this.OwnerDocument.SaveOk();
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        App.Msg("您好,必须从级别高的签名开始撤销！");
                                    }
                                }
                            }
                            return true;
                        }
                    }
                    else if (this.Name == "护士签名" || this.Name == "普通护士签名")
                    {
                        if (this.Name == "护士签名")
                        {
                            if (this.ID == App.UserAccount.UserInfo.User_id)
                            {
                                frmUpdateCancelSign fucs = new frmUpdateCancelSign();
                                fucs.ShowDialog();
                                if (fucs.Revocation)
                                {
                                    this.ID = "";
                                    this.Text = "";
                                    this.OwnerDocument.ContentChanged();
                                    //this.OwnerDocument.SaveOk();
                                }
                            }
                            else if (this.ID != "" && this.Text.Length > 1)
                            {
                                Class_DocSign hsSign = App.InSerterHighLevelSign_Nurse("N", this.ID);
                                if (hsSign != null)
                                {
                                    this.ID = hsSign.Userid;
                                    this.Text = hsSign.Username;
                                    this.OwnerDocument.ContentChanged();
                                    //this.OwnerDocument.SaveOk();
                                }
                            }
                            else
                            {
                                this.ID = App.UserAccount.UserInfo.User_id;
                                this.Text = App.UserAccount.UserInfo.User_name;
                                this.OwnerDocument.ContentChanged();
                                //this.OwnerDocument.SaveOk();
                            }
                        }
                        else if (this.Name == "普通护士签名")
                        {
                            ArrayList hszlist = this.OwnerDocument.GetQmList("护士长签名");
                            if (hszlist != null && hszlist.Count > 0)
                            {
                                ZYTextInput hszInput = (ZYTextInput)hszlist[0];
                                if (hszInput.Text.Length > 5)
                                {
                                    App.Msg("护士长已经签字了，请先撤销护士长签字！");
                                    return true;
                                }
                            }
                            if (this.ID != "" && this.Text.Length > 5)
                            {
                                frmUpdateCancelSign fucs = new frmUpdateCancelSign();
                                fucs.ShowDialog();
                                if (fucs.Revocation)
                                {
                                    Class_DocSign hsSign = App.InSerterHighLevelSign_Nurse("N", this.ID);
                                    if (hsSign != null)
                                    {
                                        this.ID = hsSign.Userid;
                                        this.Text = "        " + hsSign.Username;
                                        this.OwnerDocument.ContentChanged();
                                        this.OwnerDocument.SaveOk();
                                    }
                                }
                            }
                        }
                        return true;
                    }
                    else if (name == "护士长签名")
                    {
                        using (frmUpdateCancelSign fucs = new frmUpdateCancelSign())
                        {
                            fucs.ShowDialog();
                            if (fucs.Revocation)
                            {
                                if (this.ID == App.UserAccount.UserInfo.User_id)
                                {
                                    this.ID = "";
                                    this.Text = "";
                                    this.OwnerDocument.ContentChanged();
                                    this.OwnerDocument.SaveOk();
                                }
                                else
                                {
                                    Class_DocSign docSign = App.InSerterHighLevelSign_Nurse("");
                                    if (docSign.Userid == this.ID)
                                    {
                                        this.ID = "";
                                        this.Text = "";
                                        this.OwnerDocument.ContentChanged();
                                        this.OwnerDocument.SaveOk();
                                    }
                                    else
                                    {
                                        App.Msg("您输入的账号密码不匹配该签名！");
                                    }
                                }
                            }
                            this.OwnerDocument.ContentChanged();
                            return true;
                        }
                    }
                    else if (this.Name == "补充修正上级医师签名")
                    {
                        int signInput = this.Parent.ChildElements.IndexOf(this);
                        ZYTextInput input = (ZYTextInput)this.Parent.ChildElements[signInput + 1];
                        if (this.Text.Length < 5)
                        {
                            if (App.GetTheHighLevelUserId(input.ID, App.UserAccount.UserInfo.User_id) == App.UserAccount.UserInfo.User_id)
                            {
                                this.Text = App.UserAccount.UserInfo.U_tech_post_name + "：      " + App.UserAccount.UserInfo.User_name;
                                ZYTextParagraph paragraph2 = (ZYTextParagraph)this.Parent.ChildElements[signInput + 2];
                                ZYTextParagraph paragraph = new ZYTextParagraph();
                                paragraph.OwnerDocument = this.OwnerDocument;
                                paragraph.Parent = this;
                                paragraph.LeftChars = paragraph2.LeftChars;
                                this.ChildElements.Insert(this.ChildElements.Count - 1, paragraph);

                                this.ID = App.UserAccount.UserInfo.User_id;
                                this.OwnerDocument.ContentChanged();
                                this.OwnerDocument.SaveOk();
                                return true;
                            }
                            else
                            {
                                Class_DocSign docSign = App.InSerterHighLevelSign("S");
                                if (docSign != null)
                                {
                                    if (App.GetTheHighLevelUserId(input.ID, docSign.Userid) == docSign.Userid)
                                    {
                                        //this.Text = "  " + docSign.U_tech_post_name + "：" + docSign.Username;

                                        this.Text = docSign.U_tech_post_name + "：      " + docSign.Username;
                                        ZYTextParagraph paragraph2 = (ZYTextParagraph)this.Parent.ChildElements[signInput + 2];
                                        ZYTextParagraph paragraph = new ZYTextParagraph();
                                        paragraph.OwnerDocument = this.OwnerDocument;
                                        paragraph.Parent = this;
                                        paragraph.LeftChars = paragraph2.LeftChars;
                                        this.ChildElements.Insert(this.ChildElements.Count - 1, paragraph);
                                        this.ID = docSign.Userid;
                                        this.OwnerDocument.ContentChanged();
                                        this.OwnerDocument.SaveOk();
                                        return true;
                                    }
                                    else
                                    {
                                        App.Msg("输入账户的级别不够！");
                                        return true;
                                    }
                                }
                            }
                            return true;
                        }
                        else
                        {
                            using (frmUpdateCancelSign fucs = new frmUpdateCancelSign())
                            {
                                fucs.ShowDialog();
                                if (fucs.Revocation)
                                {
                                    if (this.ID == App.UserAccount.UserInfo.User_id)
                                    {
                                        this.ID = "";
                                        this.Text = "";
                                        this.OwnerDocument.ContentChanged();
                                        this.OwnerDocument.SaveOk();
                                    }
                                    else
                                    {
                                        Class_DocSign docSign = App.InSerterHighLevelSign("S");
                                        if (docSign.Userid == this.ID)
                                        {
                                            this.ID = "";
                                            this.Text = "";
                                            this.OwnerDocument.ContentChanged();
                                            this.OwnerDocument.SaveOk();
                                        }
                                        else
                                        {
                                            App.Msg("您输入的账号密码不匹配该签名！");
                                        }
                                    }
                                }
                                this.OwnerDocument.ContentChanged();
                                return true;
                            }
                        }
                    }
                    else if (this.Name == "医师签名")
                    {
                        if (this.ID == App.UserAccount.UserInfo.User_id)
                        {
                            frmUpdateCancelSign fucs = new frmUpdateCancelSign();
                            fucs.ShowDialog();
                            if (fucs.Revocation)
                            {
                                this.ID = "";
                                this.Text = "";
                                this.OwnerDocument.ContentChanged();
                                //this.OwnerDocument.SaveOk();
                            }
                        }
                        else if (this.ID != "" && this.Text.Length > 1)
                        {
                            Class_DocSign hsSign = App.InSerterHighLevelSign();
                            if (hsSign != null)
                            {
                                this.ID = hsSign.Userid;
                                this.Text = "        " + hsSign.Username;
                                this.OwnerDocument.ContentChanged();
                                //this.OwnerDocument.SaveOk();
                            }
                        }
                        else
                        {
                            this.ID = App.UserAccount.UserInfo.User_id;
                            this.Text = "        " + App.UserAccount.UserInfo.User_name;
                            this.OwnerDocument.ContentChanged();
                            //this.OwnerDocument.SaveOk();
                        }
                    }
                    else if (this.Name == "补充修正医师签名")
                    {
                        using (frmUpdateAndCancle fua = new frmUpdateAndCancle())
                        {
                            fua.ShowDialog();
                            if (fua.Action == "xg")
                            {
                                Class_DocSign firstSign = App.InSerterHighLevelSign("S", this.ID);
                                if (firstSign != null)
                                {
                                    this.ID = firstSign.Userid;
                                    this.Text = "  " + firstSign.U_tech_post_name + "：" + firstSign.Username;
                                    this.OwnerDocument.ContentChanged();
                                    this.OwnerDocument.SaveOk();
                                    return true;
                                }
                            }
                            else if (fua.Action == "cx")
                            {
                                //ZYTextInput input = (ZYTextInput)this.Parent.ChildElements[this.Parent.ChildElements.IndexOf(this) - 1];

                                //if (input.Text.Length > 5)
                                //{
                                //    App.Msg("请先撤销该诊断上级医师签名！");
                                //    return true;
                                //}
                                if (this.ID == App.UserAccount.UserInfo.User_id)
                                {
                                    base.OwnerDocument.RemoveOkSignToId(this);
                                    this.OwnerDocument.ContentChanged();
                                    this.OwnerDocument.SaveOk();
                                    return true;
                                }
                                else
                                {
                                    Class_DocSign cdSign = App.InSerterHighLevelSign("S");
                                    if (cdSign != null)
                                    {
                                        if (cdSign.Userid == this.ID)
                                        {
                                            base.OwnerDocument.RemoveOkSignToId(this);
                                            this.OwnerDocument.ContentChanged();
                                            this.OwnerDocument.SaveOk();
                                            return true;
                                        }
                                    }
                                    this.OwnerDocument.ContentChanged();
                                    return true;
                                }
                            }
                        }
                    }
                    return true;
                    #endregion
                }
            }
            return base.HandleDblClick(x, y, Button);
        }

        public override bool HandleClick(int x, int y, MouseButtons Button)
        {
            if (this.Contains(x, y) && (base.myChildElements.Count == 1))
            {
                base.myOwnerDocument.Content.AutoClearSelection = true;
                base.myOwnerDocument.Content.MoveSelectStart(base.myChildElements[0] as ZYTextElement);
                return true;
            }
            return false;
        }

        //public override bool HandleMouseMove(int x, int y, MouseButtons Button)
        //{
        //    if (this.Contains(x, y))
        //    {
        //        string head = "";
        //        if (this.SelectType == "0")
        //        {
        //            head = "复杂元素";
        //        }
        //        else if (this.SelectType == "1")
        //        {
        //            head = "简单元素";
        //        }
        //        else
        //        {
        //            head = "自定义输入域";
        //        }
        //        base.myOwnerDocument.OwnerControl.setToolTip(head + ":" + this.Name, this.Sign, "双击选择", this.Bounds, this);
        //        //return true;
        //    }
        //    return base.HandleMouseMove(x, y, Button);
        //}

        public override bool HandleMouseMove(int x, int y, MouseButtons Button)
        {
            if (this.OwnerDocument.Info.ShowAll && this.Contains(x, y))
            {
                string head = "";
                if (this.Name != null && this.Name.Contains("签名"))
                {
                    if (this.SelectType == "0")
                    {
                        head = "复杂元素";
                    }
                    else if (this.SelectType == "1")
                    {
                        head = "简单元素";
                    }
                    else
                    {
                        head = "自定义输入域";
                    }
                    //if()
                    string logIp = string.Empty;
                    if (this.CreatorIndex >= 0)
                    {
                        ZYTextSaveLog log2 = this.OwnerDocument.SaveLogs.GetSaveLog(this.CreatorIndex);
                        logIp = "ip:" + log2.UserIP;
                    }
                    base.myOwnerDocument.OwnerControl.setToolTip(head + ":" + this.Name, this.Sign + logIp, "双击选择", this.Bounds, this);
                    //return true;
                }
            }
            return base.HandleMouseMove(x, y, Button);
        }

        public string cFormat
        {
            get
            {
                return base.Attributes.GetString("format");
            }
            set
            {
                base.Attributes.SetValue("format", value);
            }
        }

        public override bool isField()
        {
            return true;
        }

        protected override void OnChildElementsChange()
        {
            this.bolValueFormatCheck = this.TestValueFormat();
            base.RaiseOnChangeEvent();
            base.myOwnerDocument.ElementsDirty = true;
        }

        public override bool RefreshSize()
        {
            int num = 0;
            int height = 0;
            if (base.myLastElement != null)
                base.myLastElement.RefreshSize();
            foreach (ZYTextElement element in base.myChildElements)
            {
                if (element.Visible)
                {
                    element.RefreshSize();
                    num += element.Width;
                    if (height < element.Height)
                    {
                        height = element.Height;
                    }
                }
            }
            if (height < base.myOwnerDocument.View.DefaultRowHeight())
            {
                height = base.myOwnerDocument.View.DefaultRowHeight();
            }
            if (!base.myOwnerDocument.Info.Printing)
            {
                this.Width = 6;
            }
            else
                this.Width = 0;
            base.Height = height;
            return true;
        }

        public void setMoveStart()
        {
            base.myOwnerDocument.Content.AutoClearSelection = true;
            base.myOwnerDocument.Content.MoveSelectStart(base.myLastElement.Index + 1);
        }
        public override bool RefreshView()
        {
            bolPass = ((this.OwnerDocument.Info.Printing ? this.IntLength + 1 : this.IntLength) < this.minLength ? true : false);
            return base.RefreshView();
        }

        public override void ResetViewState()
        {
            base.bolStandOutBack = false;
            if ((base.myOwnerDocument.Content.SelectLength == 0) && (base.myChildElements.Contains(base.myOwnerDocument.Content.CurrentElement) || (base.myOwnerDocument.CurrentHoverElement == this)))
            {
                base.bolStandOutBack = true;
            }
        }

        public bool TestValueFormat()
        {
            this.bolValueFormatCheck = this.myFormat.Test(this.ToZYString());
            return this.bolValueFormatCheck;
        }

        public override string ToZYString()
        {
            if (base.myChildElements.Count == 1)
            {
                return "";
            }
            return (base.ToZYString() + this.Unit);
        }

        //public override bool ToXML(XmlElement myElement)
        //{
        //    //this.UpdateID();
        //    return base.ToXML(myElement);
        //}

        public override void UpdateAttrubute()
        {
            base.UpdateAttrubute();
            KB_List kBList = ZYKBBuffer.Instance.GetKBList(this.ListSource);
            if (kBList != null)
            {
                this.Unit = kBList.Desc;
            }
        }

        public override void UpdateBounds()
        {
            int num = 0;
            foreach (ZYTextElement element in base.myChildElements)
            {
                num += element.Width + element.WidthFix;
            }
        }

        public string DisplayName
        {
            get
            {
                return "";
            }
            set
            {
                base.myAttributes.SetValue("displayname", value);
                this.Text = value;
                if (base.myLastElement is ZYTextInputEnd)
                {
                    (base.myLastElement as ZYTextInputEnd).UpdateTitle();
                }
            }
        }

        public override bool EnableTypeSet
        {
            get
            {
                return true;
            }
        }

        public override System.Drawing.Font Font
        {
            get
            {
                if (this.myFont == null)
                {
                    this.myFont = base.myOwnerDocument.View._CreateFont(this.FontName, this.FontSize, true, this.FontItalic, this.FontUnderLine);
                }
                return this.myFont;
            }
            set
            {
                this.FontName = value.Name;
                this.FontSize = value.Size;
                this.FontBold = value.Bold;
                this.FontItalic = value.Italic;
                this.FontUnderLine = value.Underline;
            }
        }

        public override bool FontBold
        {
            get
            {
                return base.Attributes.GetBool("fontbold");
            }
            set
            {
                base.Attributes.SetValue("fontbold", value);
                this.myFont = null;
            }
        }

        public override bool FontItalic
        {
            get
            {
                return base.Attributes.GetBool("fontitalic");
            }
            set
            {
                base.Attributes.SetValue("fontitalic", value);
                this.myFont = null;
            }
        }

        public override string FontName
        {
            get
            {
                return base.Attributes.GetString("fontname");
            }
            set
            {
                base.Attributes.SetValue("fontname", value);
                this.myFont = null;
            }
        }

        public int BorderStyle
        {
            get
            {
                return base.Attributes.GetInt32("border-style");
            }

            set
            {
                base.Attributes.SetValue("border-style", value);
            }
        }

        public override float FontSize
        {
            get
            {
                return base.Attributes.GetFloat("fontsize");
            }
            set
            {
                base.Attributes.SetValue("fontsize", value);
                this.myFont = null;
            }
        }

        public override bool FontUnderLine
        {
            get
            {
                return base.Attributes.GetBool("fontunderline");
            }
            set
            {
                base.Attributes.SetValue("fontunderline", value);
                this.myFont = null;
            }
        }

        public override Color ForeColor
        {
            get
            {
                return base.myAttributes.GetColor("forecolor");
            }
            set
            {
                base.myAttributes.SetValue("forecolor", value);
            }
        }

        public string Candeleted
        {
            get
            {
                return base.myAttributes.GetString("candelete");
            }
            set
            {
                base.myAttributes.SetValue("candelete", value);
            }
        }

        public StringDataFormat Format
        {
            get
            {
                return this.myFormat;
            }
            set
            {
                this.myFormat = value;
            }
        }

        //最后一个元素
        internal ZYTextInputEnd InputEnd
        {
            get
            {
                return (ZYTextInputEnd)base.myLastElement;
            }
        }

        public string ListSource
        {
            get
            {
                string str = base.myAttributes.GetString("listsource");
                return str;
            }
            set
            {
                base.myAttributes.SetValue("listsource", value);
                base.myAttributes.SetValue("id", "kb" + value.ToString());
            }
        }

        //类别
        public string SelectType
        {
            get
            {
                string type = base.myAttributes.GetString("type");
                if (type == "")
                {
                    return "3";
                }
                return type;
            }
            set
            {
                base.myAttributes.SetValue("type", value);
            }
        }

        public string Source
        {
            get
            {
                return base.myAttributes.GetString("source");
            }
            set
            {
                base.myAttributes.SetValue("source", value);
            }
        }

        public string Text
        {
            get
            {
                return this.ToZYString();
            }
            set
            {
                if (App.UserAccount != null && this.Name.Contains("签名"))
                {
                    this.Sign += "|" + App.GetSystemTime().ToString("yyyy-MM-dd HH:ss") + "签名从【" + this.Text + "】" + "修改成【" + value + "】";
                }
                ArrayList c = new ArrayList();
                c = base.myOwnerDocument.CreateChars(value, this);
                if (c != null)
                {
                    base.myChildElements.Clear();
                    base.myChildElements.AddRange(c);
                    this.AddLastElement();
                    base.myOwnerDocument.ElementsDirty = true;
                    this.RefreshSize();
                }
            }
        }

        public string Unit
        {
            get
            {
                return base.myAttributes.GetString("unit");
            }
            set
            {
                if (value != null)
                {
                    value = value.Trim();
                }
                base.myAttributes.SetValue("unit", value);
                (base.myLastElement as ZYTextInputEnd).UpdateTitle();
            }
        }

        public override int Width
        {
            get
            {
                //if (this.myLastElement != null && this.ToZYString().Length < 1)
                //{
                //    this.myLastElement.Width = 14;
                //}
                //else
                //{
                //    this.myLastElement.Width = 7;
                //}
                return base.intWidth;
            }
            set
            {
                base.intWidth = value;
            }
        }

        public class ZYTextInputEnd : ZYTextElement
        {
            internal string LastTitle = null;

            public string GetTitle()
            {
                if (this.OwnerInput.ChildCount <= 1)
                {
                    return this.OwnerInput.DisplayName;
                }
                return this.OwnerInput.Unit;
            }

            public override void HandleEnter()
            {
                ((ZYTextInput)this.Parent).ResetViewState();
                base.myOwnerDocument.RefreshElement(base.myParent);
            }

            public override void HandleLeave()
            {
                ((ZYTextInput)this.Parent).ResetViewState();
                base.myOwnerDocument.RefreshElement(base.myParent);
            }

            public override bool RefreshSize()
            {
                if (this.LastTitle != null)
                {
                    base.Width = 7 + ((int)base.myOwnerDocument.View.MeasureString(this.LastTitle, null).Width);
                }
                else
                {
                    base.Width = 7;
                }
                if (base.Parent != null)
                {
                    base.Height = base.Parent.Height;
                }
                else
                {
                    base.Height = 16;
                }
                return true;
            }

            public override bool RefreshView()
            {
                if (this.LastTitle != null)
                {
                    base.myOwnerDocument.View.DrawSingleLine2(this.LastTitle, SystemColors.WindowText, this.RealLeft, this.RealTop, this.Width);
                }
                if (!base.myOwnerDocument.Info.Printing)
                {
                    if (this.Parent is ZYTextInput)
                    {
                        if (((ZYTextInput)this.Parent).SelectType == "0")
                        {
                            base.myOwnerDocument.View.DrawString("}", this.Parent.Font, Color.DeepPink, this.RealLeft + this.Width - 9, this.RealTop);
                        }
                        else
                        {
                            base.myOwnerDocument.View.DrawString("]", this.Parent.Font, Color.DarkCyan, this.RealLeft + this.Width - 9, this.RealTop);
                        }
                    }
                }
                int dy = this.Height / 2;
                return true;
            }

            public void UpdateTitle()
            {
                this.LastTitle = this.GetTitle();
            }

            public ZYTextInput OwnerInput
            {
                get
                {
                    return (ZYTextInput)base.Parent;
                }
                set
                {
                    base.myParent = value;
                }
            }
        }
    }
}

